﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using Models;


namespace BLL
{
    public class PJLineDebugManager
    {
        private PJLineDebugService objPJLineDebugService = new PJLineDebugService();

        public string InsertIsNoSucess(PJLineDebug main)
        {
            string result;
            string serialNum = GetLastSerialNum(main.OrderType,main.OrderStartSerialNum.Substring(6,2));
            if (!string.IsNullOrEmpty(serialNum))
            {
                int temp = int.Parse(serialNum.Substring(4, 4));
                temp++;
                serialNum = "4" + main.SerialNum + temp.ToString().PadLeft(4, '0');
                main.SerialNum = serialNum;
            }
            else
            {
                main.SerialNum = "4" + main.SerialNum + "0001";
            }
            int a = IsNoLineDebug(main.WorkParentId);
            if (a == 0)
            {
                InsertInfo(main);
                result = main.SerialNum;
            }
            else
            {
                result = "false";
            }
            return result;
        }
        public int InsertInfo(PJLineDebug main)
        {
            return objPJLineDebugService.InsertInfo(main);
        }
        public int UpdateInfo(PJLineDebug main)
        {
            return objPJLineDebugService.UpdateInfo(main);
        }
        public int UpdateSapAsset(string sapAsset, int workParentId)
        {
            return objPJLineDebugService.UpdateSapAsset(sapAsset, workParentId);
        }
        public int UpdateSapBill(string sapBill, int workParentId)
        {
            return objPJLineDebugService.UpdateSapBill(sapBill, workParentId);
        }
        public int UpdateStatues(int workParentId)
        {
            return objPJLineDebugService.UpdateStatues(workParentId);
        }
        public string GetLastSerialNum(string orderType, string right2)
        {
            return objPJLineDebugService.GetLastSerialNum(orderType, right2);
        }
        public PJLineDebug GetLineDebug(int workParentId)
        {
            return objPJLineDebugService.GetLineDebug(workParentId);
        }
        public int IsNoLineDebug(int workParentId)
        {
            return objPJLineDebugService.IsNoLineDebug(workParentId);
        }
    }
}
